<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\Apply\CreateApply;
use App\Models\SchoolInfo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ApplyController extends Controller
{
    /**
     * 申请开通学校
     *
     * @param CreateApply $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function create(CreateApply $request)
    {
        $applyData = $request->only('school_name', 'address');
        $applyData['user_id'] = Auth::id();
        $applyData['status'] = 0;
        SchoolInfo::create($applyData);

        return success();
    }

    /**
     * 申请列表
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function list(Request $request)
    {
        $status = (int)$request->input('status');
        $schoolInfo = SchoolInfo::where("user_id", Auth::id());
        if ($status) {
            $schoolInfo->where('status', $status);
        }
        $data = $schoolInfo->orderBy('id', 'desc')->get();

        return success($data);
    }
}